package exporter

import (
	"github.com/prometheus/client_golang/prometheus"
	"io/ioutil"
	"log"
	"os/exec"
	"time"
)

type Fault struct {
	Content string
}

var (
	fault = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "vnx_get_all_fault",
			Help: "Get All Fault Info",
		},
		[]string{"Content"},
	)
)

func FaultGauge() *prometheus.GaugeVec {
	return fault
}

func GetFaultMetrics(spIp string, user string, password string) {
	for {
		cmd := exec.Command("bash", "-c", "/opt/Navisphere/bin/naviseccli -h "+spIp+" -user "+user+" -password "+password+" -Scope 0 faults -list")
		stdout, _ := cmd.StdoutPipe()
		defer stdout.Close()
		if err := cmd.Start(); err != nil {
			log.Fatalf("cmd.Start: %v", err)
		}
		result, _ := ioutil.ReadAll(stdout) // 读取输出结果
		resData := string(result)

		fault.WithLabelValues(resData)
		time.Sleep(60 * time.Second)
	}
}
